/**
 * Created by yeso on 2015/9/24.
 */
angular.module('app.template', [
    'ngCookies'
])
.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
    $stateProvider
        .state('home', {
            'abstract': true,
            url: "/home",
            views: {
                '': {
                    templateUrl: "tpls/home.html",
                    controller: 'GetCookieController'
                },
                'topbar@home': {
                    templateUrl: "tpls/topbar.html",
                    controller: 'GetCookieController'
                },
                'main@home': {
                    templateUrl: "tpls/main.html"
                }
            }
        })
}])

//判断cookie

.controller('GetCookieController', ['$scope','$state','$cookieStore','LoginService', function($scope, $state, $cookieStore, LoginService) {
    var data = $cookieStore.get('manager_cookie');
    if (data == undefined) {
        alert("Page has expired, please login again");
        $state.go('login');
    } else {
        $scope.manager_cookie = data;
        //console.log("this is" + data.managername);
    }
}])

//清除cookie

.controller('removecookieCtrl', ['$scope','$state','$cookieStore', function($scope, $state, $cookieStore) {
    $cookieStore.remove('manager_cookie');
    $state.go('home.exit');
}])
;
